$(function () {
    var password=prompt();

   if(password=="18678899665"){
       vm.getPoint();
   }else {
       window.location.href="err.html";
   }

});

var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    },
    callback : {
        // 单击事件
        onClick : zTreeOnClick
    }
};
// 单击事件，向后台发起请求
function zTreeOnClick(event, treeId, treeNode) {
    vm.getPointInfo(treeNode.id)

}
var ztree;

var vm = new Vue({
    el:'#rrapp',
    data:{
        status:"",
        sendMessage:"",
        receiveMessage:"",
        lhpInstallationPoint:{}
    },
    methods: {
        getPoint: function(){
            //加载路段树
            $.get("baseinfo/lhpinstallationpoint/pointTree", function(r){
                ztree = $.fn.zTree.init($("#pointTree"), setting, r);
            })
        },
        getPointInfo: function(id) {
            $.get(baseURL + "baseinfo/lhpinstallationpoint/info/" + id, function (r) {
                vm.lhpInstallationPoint = r.lhpInstallationPoint;
                if(vm.lhpInstallationPoint.networkDeviceType==0){
                    vm.getSocketStatus(vm.lhpInstallationPoint.pointCode);
                }else if(vm.lhpInstallationPoint.networkDeviceType==1){
                    vm.getSocketStatus(vm.lhpInstallationPoint.networkDeviceIp);
                }

            });
        },
        getSocketStatus:function (pointCode) {
            $.get(baseURL + "socket/getSocketStatus/" + pointCode, function (r) {
                vm.status = r.status;
            });
        },
        closeSocket:function () {
            $.get(baseURL + "socket/closeSocket/" + vm.lhpInstallationPoint.pointCode, function (r) {
            });
        },
        sendInstruction:function () {
            $.post(baseURL + "socket/sendInstruction",{pointCode:vm.lhpInstallationPoint.pointCode,sendMessage:vm.sendMessage},function(r){
                vm.receiveInstruction();
            });

        },
        receiveInstruction:function () {
            $.post(baseURL + "socket/receiveInstruction",{pointCode:vm.lhpInstallationPoint.pointCode},function(r){
                vm.receiveMessage=r.message;
                console.log(r.message)
            });
        }
    }
});